package com.jc.oss.controller;

import com.alibaba.nacos.api.config.annotation.NacosValue;
import com.jc.oss.Entity.Result;
import com.jc.oss.service.FileService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Author: ASL_ly
 * @Package: com.jc.oss.controller
 * @Project: jc-club
 * @Date: 2024/10/26  13:30
 */
@RestController
public class FileContoller {

    @Resource
    private FileService fileService;

    /**
     * 查看所有桶
     * @return
     * @throws Exception
     */
    @GetMapping("/testGetAllBuckets")
    public List<String> testGetAllBuckets() throws Exception{
        return fileService.getAllBucket();
    }

    /**
     * 获取文件路径
     * @param bucketName
     * @param objectName
     * @return
     * @throws Exception
     */
    @RequestMapping("/getUrl")
    public String getUrl(String bucketName, String objectName) throws Exception{
        return fileService.getUrl(bucketName,objectName);
    }

    /**
     * 上传文件
     * @param uploadFile
     * @param bucket
     * @param objectName
     * @return
     * @throws Exception
     */
    @RequestMapping("/upload")
    public Result upload(MultipartFile uploadFile, String bucket, String objectName) throws Exception{
        String url = fileService.uploadFile(uploadFile, bucket, objectName);
        return Result.success(url);
    }


}
